package com.xingkeduo.business.user.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.CraftsmanSmsQO;
import com.xingkeduo.pojo.table.CraftsmanSmsTO;
import com.xingkeduo.util.pojo.exception.DataException;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import com.xingkeduo.util.tool.IdentityUtil.Worker;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/2/18 18:29
 **/
@Service
public class CraftsmanSmsService {
    private static final String NAMESPACE = CommonUtil.formatNamespace(CraftsmanSmsTO.class);
    @Resource(name = "mysqlUserMasterDao")
    private DatabaseAccessObject<CraftsmanSmsTO, CraftsmanSmsQO> dao;


    /**
     * 消费者分页列表
     *
     * @return : List<ConsumerTO>
     * @author : gaozifeng
     * @date : 2019年2月26日20:29:33
     */
    public List<CraftsmanSmsTO> selectList(CraftsmanSmsQO consumerQO) throws Throwable {
        return dao.select(NAMESPACE, consumerQO);
    }

    /**
     * 消费者分页列表
     *
     * @return : List<ConsumerTO>
     * @author : gaozifeng
     * @date : 2019年2月26日20:29:33
     */
    public List<Long> selectListForid(CraftsmanSmsQO consumerQO) throws Throwable {
        return dao.selectIndex(NAMESPACE, consumerQO);
    }

    /**
     * 新增消费者
     *
     * @param consumerTO:
     * @return : int
     * @author : gaozifeng
     * @date : 2019/2/19 11:27
     */
    @Transactional
    public void insert(CraftsmanSmsTO consumerTO) throws Throwable {
        consumerTO.initId(IdentityUtil.nextId(Worker.USER));
        consumerTO.setUpdatedBy(consumerTO.getId());
        consumerTO.setCreatedBy(consumerTO.getId());
        if (dao.insert(NAMESPACE, consumerTO) < 1) {
            throw new DataException(DataException.Type.FAIL, "新增消费者信息");
        }
    }

    /**
     * 查询单数据
     *
     * @param id:
     * @return : com.xingkeduo.pojo.table.ConsumerTO
     * @author : gaozifeng
     * @date : 2019/2/27 18:18
     */
    public CraftsmanSmsTO selectByPrimary(long id) throws Throwable {
        return dao.select(NAMESPACE, id);
    }


    public void update(CraftsmanSmsTO craftsmanSmsTO) throws Throwable {
        if (dao.update(NAMESPACE, craftsmanSmsTO) < 1) {
            throw new DataException(DataException.Type.FAIL, "修改发型师短信");
        }
    }

}
